# Code for Paper Calculations
## Description

This repository contains the code used to evaluate the feasibility of two-photon direct optical magnetometry using 129Xe.

The core of the code is a calculation class that computes:
    Xenon density and interaction parameters
    Two-photon transition rates
    Signal amplitude
    Noise contributions (projection, shot, detector, and technical intensity noise)
    Magnetic field sensitivity

A separate script generates Figures 2–5 of the paper using this calculation class.

Default experimental and hardware parameters are stored in JSON configuration files.

## Physical Model Overview

The model includes:
    Doppler-free two-photon excitation
    Pressure broadening
    Projection noise
    Photon shot noise (IR and UV channels)
    Detector noise (NEP and thermal)
    Relative intensity noise (RIN), corrected for common-mode rejection

All sensitivities are computed in units of T/√Hz.

## Dependencies

This code requires:
    numpy
    scipy
    matplotlib
    json (standard library)
    dataclasses (standard library)

Install the core dependencies with:

`pip install numpy scipy matplotlib`

## File Structure

The repository contains:

.
├── calculation_class.py
├── graph_creation.py
└── config/
    ├── thorlabs_config.json
    ├── laser_config.json
    ├── xenon_config.json
    └── long_pulse_config.json

### config/

This folder contains JSON configuration files specifying default parameters:

Photodetector configuration
    Responsivity
    Noise-equivalent power (NEP)
    Transimpedance gain
    Common-mode rejection ratio

Laser configuration
    Laser power
    Relative intensity noise (RIN)

Xenon configuration
    Two-photon absorption coefficient
    Natural linewidth
    Pressure broadening coefficient
    Gyromagnetic ratio

Experimental configuration

    Xenon pressure and temperature
    Polarization
    Beam waist
    Measurement time
    Number of measurements

### calculation_class.py

Defines the calculation dataclass.

On initialization:
    1. Loads configuration parameters
    2. Computes derived physical quantities
    3. Evaluates all noise contributions
    4. Computes total magnetic field sensitivity

All results are stored as attributes of the class instance.

### graph_creation.py

Imports the calculation class and generates Figures 2–5 for the paper.

Some additional figure-specific parameters are defined at the top of this script.

## Usage

To run a calculation with default parameters:
```
from calculation_class import calculation

calc = calculation()
print(calc.sensitivity)
```

To modify parameters:

```
calc = calculation(P_laser=2.0, pres_Xe_bar=5.0)
```

To reproduce figures:

```python graph_creation.py```

## Reproducibility Notes

All numerical values used in the paper figures are generated directly from this code and the configuration files included in the repository.

Changing configuration values will automatically propagate through all derived quantities.